package com.demo.my.Service;


import com.demo.my.Dao.EmployeeDao;
import com.demo.my.Entity.Employee;
import com.demo.my.Dao.DepartmentDao;
import com.demo.my.Dao.EmployeeDao;
import com.demo.my.Dao.PositionDao;
import com.demo.my.Entity.Department;
import com.demo.my.Entity.Employee;
import com.demo.my.Entity.Position;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class EmployeeService {
    private static EmployeeDao employeeDao  = new EmployeeDao();
    private static DepartmentDao departmentDao= new DepartmentDao();
    private static PositionDao positionDao= new PositionDao();

    public static void updateById(Employee i) throws Exception {
        String sql = "UPDATE employee SET employee_number = ?,employee.`name`=?,gender=?,birthday=?,employee.`password`=?,telephone=?,email=?,address=?,education=?,notes=? WHERE id=?";
        Object[] objs = {i.getEmployeeNumber(),i.getName(),i.getGender(),i.getBirthday(),i.getPassword(),
        i.getTelephone(),i.getEmail(),i.getAddress(),i.getEducation(),i.getNotes(),i.getId()};
        employeeDao.updateById(sql,objs);
    }

    public Employee getEmployee(String employeeNumber, String password) {
        return employeeDao.getEmployee(employeeNumber, password);
    }

    public static Employee getInfoById(Integer id){
        Employee info = employeeDao.getEntityById(id);
        Integer departId= info.getDepartmentNumber();
        Department departInfo = departmentDao.getEntityById(departId);
        info.setDepartment(departInfo);
        Integer positId = info.getPositionNumber();
        Position positInfo = positionDao.getEntityById(positId);
        info.setPosition(positInfo);
        return info;
    }

    public int getMaxNumber() throws SQLException {
        return employeeDao.getMaxNumber();
    }

    public void addEmployee(Employee employee) throws SQLException {
        employeeDao.addEmployee(employee);
    }

    public Employee getEmployeeById(String id) throws Exception {
        return employeeDao.getEmployeeById(id);
    }

    public void updateEmployee(Employee employee) throws SQLException {
        employeeDao.updateEmployee(employee);
    }

    public List<Employee> getEmployeeListByDid(Integer id) throws Exception {
        return employeeDao.getEmployeeListByDid(id);
    }
}
